export const urls = {
  index: '/',
  s404: '/s404',
  s403: '/s403'
} as const

export const aurls = makeIndexUrls({
  index: '/admin',
  admin: '/',
  user: '/user',
  copilot: '/copilot',
  topup: '/topup',
  order: '/order',
  log: '/log',
  settings: '/settings'
})

export const uurls = makeIndexUrls({
  index: '/user',
  star: '/star',
  copilot: '/copilot',
  copilotDetail: '/copilot/detail',
  topup: '/topup',
  order: '/order',
  settings: '/settings'
})

export const curls = makeIndexUrls({
  index: '/copilot',
  comment: '/comment',
  order: '/order',
  settings: '/settings'
})

export function makeUrls<T extends Record<string, any>>(urls: T, prefix: string = '', suffix: string = ''): T {
  const entries = Object.entries(urls).map(([k, v]) => {
    if (v instanceof Object) {
      return [k, makeUrls(v, prefix, suffix)]
    }
    return [k, prefix + v + suffix]
  })
  return Object.fromEntries(entries)
}

export function makeIndexUrls<T extends Record<string, any>>(urls: T): T {
  const entries = Object.entries(urls).map(([k, v]) => {
    if (k === 'index') return [k, v]
    if (v instanceof Object) {
      return [k, makeUrls(v, urls['index'])]
    }
    return [k, urls['index'] + v]
  })
  return Object.fromEntries(entries)
}

export function getImg(v: string) {
  return '/imgs' + v
}
